﻿using System;
using System.ServiceModel;

namespace Arete
{
    internal class EventServiceClient : DuplexClientBase<IMyContract>, IMyContract
    {
        public EventServiceClient(InstanceContext eventCntx)
            : base(eventCntx) { }

        public void DoSomethingAndFireEvent()
        { Channel.DoSomethingAndFireEvent(); }

        public void SendMessageAndFireEvent(string message)
        { Channel.SendMessageAndFireEvent(message); }

        public void SubscribeEvent() { Channel.SubscribeEvent(); }
    }

    class MySubscriber : IMyEvents
    {
       public void Event1()
        {
            Console.WriteLine(
                "Event is subscribed from the service at {0}",
                DateTime.Now);
        }

       public void MessageEvent(object obj, MessageEventArgs e)
        {
            Console.WriteLine(
                "Event {0} is subscribed from the service at {1}",
                 e.MessageText, DateTime.Now);
        }
    }
}
